package com.bondar.RestLogin.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bondar.RestLogin.entities.User;
import com.bondar.RestLogin.repositories.Rolerepository;
import com.bondar.RestLogin.repositories.UserRepository;

@Component
public class UserService {
	
	@Autowired UserRepository userRepository;
	@Autowired Rolerepository roleRepository;
	
	public List<User> findAll() {
		 List<User> users = userRepository.findAll();
		 
		 for (User user : users) {
			user.setRoles( roleRepository.findAllRolesByUser(user) );
		 }
		 
		 return users;
	}

	public User findUserByName(String name) {
		return userRepository.findUserByName(name);
	}
}
